package com.jdbc.tester;

import java.io.*;
import java.sql.*;
import java.util.Properties;

public class JDBCClient {

  public void execute(Properties props) throws SQLException,
      FileNotFoundException, IOException {
     String username = props.getProperty("userid");
     String password = props.getProperty("password");
     String url = props.getProperty("url");

    Connection con = getJDBCConnection(url, username, password);
    
    if (con == null) {
      System.out.println("Could not get Connection");
      return;
    }

    DatabaseMetaData meta = con.getMetaData();
    String productVersion = meta.getDatabaseProductVersion();
    System.out.println("Successfully connected to remote database: " + productVersion );
    System.out.println("Client Driver Name : " + meta.getDriverName());
    System.out.println("Client Driver Version : " + meta.getDriverVersion());

  }

  private Connection getJDBCConnection(String url, String user, String password) {
    Connection con = null;
    try {
      Class.forName(com.teradata.jdbc.TeraDriver.class.getName());
    } catch (ClassNotFoundException e) {
      System.err.print("ClassNotFoundException: ");
      System.err.println(e.getMessage());
    }
    try {
      con = DriverManager.getConnection(url, user, password);
    } catch (SQLException ex) {
      System.err.println("SQLException: " + ex.getMessage());
    }
    return con;
  }

}
